# encoding:utf-8
# 增加 sim, iccid 从文件导入
# author yeyi
import requests
import csv

# 联调
#url = "http://10.2.1.9/gq-bss/v1/bss/tbox/add"
# 开发
url = "http://193.112.139.106:8080/v1/bss/tbox/add"
headers = {
    'Content-Type': "application/json"
}

f = open(r"tbox-add-iccid.txt")
line = f.readline()
sns = []
while line:
    sns.append(line.split()[0])
    line = f.readline()
f.close()

with open("tbox-add-iccid.csv", "w") as csvfile:
    writer = csv.writer(csvfile)
    writer.writerow(["sn", "imei", "callNumber"])
    callNumber = range(15157910100, 15157910199)
    imei = range(400024985000200, 400024985000299)
    i = 0
    for (phone, ims) in zip(callNumber, imei):
        print(sns[i], phone, ims)
        payload = "{\n" +\
            "    \"sn\":\""+str(sns[i])+"\",\n" +\
            "    \"callNumber\":\""+str(phone)+"\",\n" +\
            "    \"imei\":\""+str(ims)+"\",\n" +\
            "    \"terminalType\":\"0\",\n" +\
            "    \"type\":3" +\
            "}"
        print(payload)
        response = requests.request(
            "POST", url, data=payload.encode('utf-8'), headers=headers)
        print(str(response.content))
        writer.writerow(["1", str(sns[i]), str(phone), str(ims)])
        i = i+1
        if i >= len(sns):
            break
